.TH std::basic_string_view::back 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_string_view::back \- std::basic_string_view::back

.SH Synopsis
   constexpr const_reference back() const;  \fI(since C++17)\fP

   Returns reference to the last character in the view. The behavior is undefined if
   empty() == true.

.SH Parameters

   \fI(none)\fP

.SH Return value

   Reference to the last character, equivalent to operator[](size() - 1).

.SH Complexity

   Constant.

.SH Example


// Run this code

 #include <iostream>
 #include <string_view>

 int main()
 {
     for (std::string_view str{"ABCDEF"}; !str.empty(); str.remove_suffix(1))
         std::cout << str.back() << ' ' << str << '\\n';
 }

.SH Output:

 F ABCDEF
 E ABCDE
 D ABCD
 C ABC
 B AB
 A A

.SH See also

   front accesses the first character
         \fI(public member function)\fP
   empty checks whether the view is empty
         \fI(public member function)\fP
   back  accesses the last character
   (DR*) \fI(public member function of std::basic_string<CharT,Traits,Allocator>)\fP
